﻿Imports System
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Drawing.Design
Imports System.Runtime.InteropServices
Imports System.Workflow.ComponentModel
Imports System.Workflow.ComponentModel.Compiler

Namespace System.Workflow.Activities
    <Designer(GetType(StateMachineWorkflowDesigner), GetType(IRootDesigner)), SRDescription("StateMachineWorkflowActivityDescription"), ToolboxItem(False), ToolboxBitmap(GetType(StateMachineWorkflowActivity), "Resources.StateMachineWorkflowActivity.png"), ActivityValidator(GetType(StateActivityValidator)), SRCategory("Standard"), SRDisplayName("StateMachineWorkflow"), Designer(GetType(StateMachineWorkflowDesigner), GetType(IDesigner)), ComVisible(False)> _
    Public Class StateMachineWorkflowActivity
        Inherits StateActivity
        ' Methods
        Public Sub New()
        End Sub

        Public Sub New(ByVal name As String)
            MyBase.New(name)
        End Sub


        ' Properties
        <SRDescription("CompletedStateDescription"), Editor(GetType(StateDropDownEditor), GetType(UITypeEditor)), DefaultValue("")> _
        Public Property CompletedStateName As String
            Get
                Return CStr(MyBase.GetValue(StateMachineWorkflowActivity.CompletedStateNameProperty))
            End Get
            Set(ByVal value As String)
                MyBase.SetValue(StateMachineWorkflowActivity.CompletedStateNameProperty, value)
            End Set
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public ReadOnly Property CurrentStateName As String
            Get
                Dim executionState As StateMachineExecutionState = Me.ExecutionState
                If (executionState Is Nothing) Then
                    Return Nothing
                End If
                Return executionState.CurrentStateName
            End Get
        End Property

        <SRCategory("Conditions"), SRDescription("DynamicUpdateConditionDescr")> _
        Public Property DynamicUpdateCondition As ActivityCondition
            Get
                Return [TryCast](WorkflowChanges.GetCondition(Me),ActivityCondition)
            End Get
            Set(ByVal value As ActivityCondition)
                WorkflowChanges.SetCondition(Me, value)
            End Set
        End Property

        Friend ReadOnly Property ExecutionState As StateMachineExecutionState
            Get
                Return DirectCast(MyBase.GetValue(StateActivity.StateMachineExecutionStateProperty), StateMachineExecutionState)
            End Get
        End Property

        <Editor(GetType(StateDropDownEditor), GetType(UITypeEditor)), DefaultValue(""), ValidationOption(ValidationOption.Optional), SRDescription("InitialStateDescription")> _
        Public Property InitialStateName As String
            Get
                Return CStr(MyBase.GetValue(StateMachineWorkflowActivity.InitialStateNameProperty))
            End Get
            Set(ByVal value As String)
                MyBase.SetValue(StateMachineWorkflowActivity.InitialStateNameProperty, value)
            End Set
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Public ReadOnly Property PreviousStateName As String
            Get
                Dim executionState As StateMachineExecutionState = Me.ExecutionState
                If (executionState Is Nothing) Then
                    Return Nothing
                End If
                Return executionState.PreviousStateName
            End Get
        End Property


        ' Fields
        Public Shared ReadOnly CompletedStateNameProperty As DependencyProperty = DependencyProperty.Register("CompletedStateName", GetType(String), GetType(StateMachineWorkflowActivity), New PropertyMetadata(DependencyPropertyOptions.Metadata))
        Friend Const CompletedStateNamePropertyName As String = "CompletedStateName"
        Public Shared ReadOnly InitialStateNameProperty As DependencyProperty = DependencyProperty.Register("InitialStateName", GetType(String), GetType(StateMachineWorkflowActivity), New PropertyMetadata(DependencyPropertyOptions.Metadata))
        Friend Const InitialStateNamePropertyName As String = "InitialStateName"
        Public Const SetStateQueueName As String = "SetStateQueue"
    End Class
End Namespace

